﻿/*
 *    Copyright [2010] [Daniel Sawan]
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * 
 */

package com.kikoulol.jarmory.extractor;

import java.util.List;

import com.kikoulol.jarmory.extractor.enums.Regions;
import com.kikoulol.jarmory.extractor.enums.LadderTypes;
import com.kikoulol.jarmory.extractor.xml.TeamInfo;
import com.kikoulol.jarmory.extractor.xml.BattleGroups;
import com.kikoulol.jarmory.extractor.xml.CharacterSheet;

public class Armory
{
	private Regions region;

	/**
	 * 
	 * @param region
	 */
	public Armory(Regions region)
	{
		this.region = region;
	}

	public List<BattleGroup> getBattleGroups()
	{
		return new BattleGroups(this.region).getBattleGroups();
	}

	/**
	 * 
	 * @param realm
	 * @param name
	 * @return
	 */
	public CharacterSheet getCharacter(String charUrl)
	{
		return new CharacterSheet(this.region, charUrl);
	}

	public static CharacterSheet getPlayer(String charUrl)
	{
		 String regionValue = charUrl.substring(0,charUrl.indexOf("character-sheet.xml"));
		 String charUrlValue = charUrl.substring(charUrl.indexOf("r="));
		 Regions selectedRegion = null;
		 
		 for(Regions region : Regions.values()) {
			 if(region.url().equalsIgnoreCase(regionValue)) {
				 selectedRegion = region;
				 break;
			 }
		 }
		 
		return new CharacterSheet(selectedRegion,charUrlValue);
	}

	/**
	 * 
	 * @param battleGroupName
	 * @param ladderType
	 * @return
	 */
	public Ladder getLadder(String battleGroupName, LadderTypes ladderType)
	{
		return new Ladder(this.region, battleGroupName, ladderType);
	}

	public Regions getRegion()
	{
		return region;
	}

	/**
	 * 
	 * @param teamQueryString
	 * @return
	 */
	public TeamInfo getTeam(String teamQueryString)
	{
		return new TeamInfo(this.region, teamQueryString);
	}
}
